package com.finer.service.impl;

import com.finer.entity.buy.SupplierPrice;
import com.finer.dao.SupplierPriceDao;
import com.finer.service.SupplierPriceService;
import org.springframework.stereotype.Service;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;

import javax.annotation.Resource;

/**
 * 供应报价表(SupplierPrice)表服务实现类
 *
 * @author makejava
 * @since 2024-10-21 10:20:42
 */
@Service("supplierPriceService")
public class SupplierPriceServiceImpl implements SupplierPriceService {
    @Resource
    private SupplierPriceDao supplierPriceDao;

    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    @Override
    public SupplierPrice queryById(Integer id) {
        return this.supplierPriceDao.queryById(id);
    }

    /**
     * 分页查询
     *
     * @param supplierPrice 筛选条件
     * @param pageRequest      分页对象
     * @return 查询结果
     */
    @Override
    public Page<SupplierPrice> queryByPage(SupplierPrice supplierPrice, PageRequest pageRequest) {
        long total = this.supplierPriceDao.count(supplierPrice);
        return new PageImpl<>(this.supplierPriceDao.queryAllByLimit(supplierPrice, pageRequest), pageRequest, total);
    }

    /**
     * 新增数据
     *
     * @param supplierPrice 实例对象
     * @return 实例对象
     */
    @Override
    public SupplierPrice insert(SupplierPrice supplierPrice) {
        this.supplierPriceDao.insert(supplierPrice);
        return supplierPrice;
    }

    /**
     * 修改数据
     *
     * @param supplierPrice 实例对象
     * @return 实例对象
     */
    @Override
    public SupplierPrice update(SupplierPrice supplierPrice) {
        this.supplierPriceDao.update(supplierPrice);
        return this.queryById(supplierPrice.getId());
    }

    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer id) {
        return this.supplierPriceDao.deleteById(id) > 0;
    }
}
